//
//  ViewController.m
//  DYPlayer
//
//  Created by 黄德玉 on 2017/7/4.
//  Copyright © 2017年 none. All rights reserved.
//

#import "ViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
#import "DYBrightnessView.h"
#import "DYVolumeView.h"

typedef NS_ENUM(NSInteger,GestureType) {
    GestureTypeLeft = 0,
    GestureTypeRight
};

@interface ViewController ()

@property (nonatomic,assign) CGPoint gestureBeginPoint;
@property (nonatomic,assign) GestureType gestureType;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor brownColor];
    [self _addGesture];
}

- (void)_addGesture{
    UIPanGestureRecognizer * gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)];
    [self.view addGestureRecognizer:gesture];
}

-(void)gestureAction:(UIPanGestureRecognizer *)gesture{
    switch (gesture.state) {
        case UIGestureRecognizerStateBegan:
            self.gestureBeginPoint = [gesture locationInView:self.view];
            if (self.gestureBeginPoint.x < [UIScreen mainScreen].bounds.size.width * .5) {
                self.gestureType = GestureTypeLeft;
            }else{
                self.gestureType = GestureTypeRight;
            }
            break;
        case UIGestureRecognizerStateChanged:{
            CGPoint currentPoint = [gesture locationInView:self.view];
            CGFloat offset = (self.gestureBeginPoint.y - currentPoint.y);
            if (self.gestureType == GestureTypeLeft) {//亮度调节
                [DYBrightnessView updateBrightnessWithValue:offset / 500];
            }else{                                    //音量调节
                [DYVolumeView updateVolumeWithValue:offset / 500];
            }
            self.gestureBeginPoint = currentPoint;
        }
            break;
        case UIGestureRecognizerStateEnded:
            break;
        default:
            break;
    }
}

//- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    AVPlayerViewController * VC = [[AVPlayerViewController alloc] init];
//    AVPlayer * player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:@"http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4"]];
//    VC.player = player;
//    [self presentViewController:VC animated:YES completion:nil];
//}


@end
